package keni.html.android.framework.connectionChannel;

public abstract class SinkBase implements IChannelSink {

	IChannelSink previous;
	IChannelSink next;
	public void setPreviousChannelSink(IChannelSink previous)
	{
		this.previous=previous;
	}
	public void setNextChannelSink(IChannelSink next)
	{
		this.next=next;
	}
	
	public IChannelSink getNextChannelSink()
	{
		return next;
	}
	public IChannelSink getPreviousChannelSink()
	{
		return previous;
	}
	Header responseHeader=new Header();
	ResponseMessage responseMessage=new ResponseMessage();
	public void processRequest(RequestMessage message, Header header) {
		
		doProcessRequest(message,header,responseMessage,responseHeader);
		IChannelSink nextSink=getNextChannelSink();
		if(nextSink!=null)
		{
			nextSink.processRequest(message, header);
		}
		processResponse(message, header, responseMessage, responseHeader);
		
	}
	
	public void doProcessRequest(RequestMessage message, Header header,ResponseMessage outResponseMsg, Header outResponseHeaders) {
		
	}
	
	public void processResponse(RequestMessage requestMsg, Header requestHeaders,
			ResponseMessage responseMsg, Header responseHeaders) {
		doProcessResponse(requestMsg,requestHeaders,responseMsg,responseHeaders);
		
		IChannelSink preChannelSink=getPreviousChannelSink();
		
		if(preChannelSink!=null)
		{
			preChannelSink.processResponse(requestMsg, requestHeaders, responseMsg, responseHeaders);
		}
		
		
	}
	
	public void doProcessResponse(RequestMessage requestMsg, Header requestHeaders,
			ResponseMessage responseMsg, Header responseHeaders){
		
		
	}
	
   public  ResponseMessage getResponseMessage(){
	   return responseMessage;
   }
   public  Header getResponseHeader()
   {
	   return responseHeader;
   }
	
}
